package me.luraframework.db.util;

import me.luraframework.commons.model.PageDto;
import org.springframework.data.domain.Page;

import java.util.function.Function;

/**
 * @ description: PageUtils
 * @ author: Liu Ran
 * @ data: 12/30/22 15:16
 */
public class PageUtils {

    public static <T> PageDto<T> toPageDto(Page<T> page) {
        return PageDto.of(page.getContent(), page.getTotalElements());
    }

    public static <T, V> PageDto<V> toPageDto(Page<T> page, Function<T, V> converter) {
        return PageDto.of(page.map(converter).getContent(), page.getTotalElements());
    }
}
